local function _d_resetskilltree(player)
    if not (player and TheWorld.ismastersim) then
        return
    end

    local skilltreeupdater = player.components.skilltreeupdater
    local skilldefs = require("prefabs/skilltree_defs").SKILLTREE_DEFS[player.prefab]
    if skilldefs ~= nil then
        local attempts = 50
        while attempts > 0 do -- FIXME(JBK): This needs to be done in skilltreeupdater and carefully handled for server and client sync.
            local keepgoing = false
            for skill, data in pairs(skilldefs) do
                if data.rpc_id then
                    if skilltreeupdater:IsActivated(skill) then
                        keepgoing = true
                        skilltreeupdater:DeactivateSkill(skill)
                    end
                end
            end
            if not keepgoing then
                break
            end
            attempts = attempts - 1
        end
    end

    skilltreeupdater:AddSkillXP(3)
end

AddPlayerPostInit(function(inst)
    if not TheWorld.ismastersim then return end
    inst:DoTaskInTime(2, function()
        _d_resetskilltree(inst)
    end)
end)
